package com.lxq.test1712.main02;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        int flag=0,num=-1;
//        int[] a = new int[n];
        LinkedList<Integer> personList = new LinkedList<>();

        for (int i=0 ;i<n ;i++){
            personList.addLast(i+1);//头插法
        }
//        System.out.println(personList);
        do {
//            System.out.println("第"+(flag+1)+"次：");
            num = (num+1) % personList.size();
//            System.out.print("num: "+(num+1));
            flag++;
//            System.out.println("  flag: "+flag);
            if ((String.valueOf(flag).endsWith(String.valueOf(k)))||(flag%k==0)){
//                System.out.println("删除！");
                personList.remove(num--);
            }
//            System.out.println("personList : "+personList);
        }while (personList.size()>1);

        System.out.println(personList.get(0));

    }
}
